package logic

import (
	"context"

	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

	"2106A-zg6/baidu/srv/internal/svc"
	"2106A-zg6/baidu/srv/models"
	"2106A-zg6/baidu/srv/pb/baidu"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
	return &GetUserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserInfoLogic) GetUserInfo(in *baidu.UserInfoRequest) (*baidu.UserInfoResponse, error) {

	info, err := models.GetUserInfo(in.UserId)
	if err != nil {
		return nil, status.Errorf(codes.Canceled, err.Error())
	}

	return &baidu.UserInfoResponse{
		UserInfo: ModelRespLogin(info),
	}, nil
}
